
<template>
    <div class="mainContent">
        <el-tree
            :data="data"
            style="height: 300px; overflow: auto"
            show-checkbox
            node-key="id"
            :props="defaultProps"
            :default-expanded-keys="[defaultId]"
            :check-strictly="true"
            ref="tree"
        >
        </el-tree>
    </div>
</template>

<script>
import customButton from '@/components/customComponents/customForm/customButton'
import {AjaxCommon} from '@/libs/apiCommon'
import {PopupCommon} from '@/libs/popupCommon'
import moment from 'moment'
export default {
    name: 'schemeConfiguration',
    components: {customButton},
    data() {
        return {
            radio: '0',
            time: moment().format('YYYY-MM-DD'),
            defaultId: '',
            checked: true,
            data: [],
            acName: '',
            defaultProps: {
                children: 'children',
                label: 'text'
            }
        }
    },
    computed: {},
    created() {
        this.getData()
    },
    methods: {
        getSelectData() {
            var checkedNodes = this.$refs.tree.getCheckedNodes(true)
            return checkedNodes
        },
        formatData(params) {
            let data = params
            data.map((item) => {
                if (item.hasOwnProperty('children') && item.children.length > 0) {
                    item.disabled = true
                    this.formatData(item.children)
                }
            })
            return data
        },
        getData() {
            let self = this
            self.data = []
            AjaxCommon(`/api/OpenAccount/GetTreeNodes?type=${this.radio}`, 'get', null).then((res) => {
                if (res?.data?.Code == 200) {
                    let data = res.data.Message
                    data = this.formatData(data)
                    self.data = data
                    self.defaultId = data?.[0]?.id ?? ''
                } else {
                    const msg = res?.data?.Message
                    if (msg) {
                        PopupCommon.notify('error', msg)
                    }
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.mainContent {
    max-height: 400px;
    overflow-y: auto;
}
</style>
